<?php
namespace app\hospital\controller;
use app\BaseController;
use app\hospital\model\doctoruser;
use app\hospital\model\patientreserve;
use think\facade\Db;
use think\facade\Session;
use think\facade\View;
use think\facade\Request;
use app\hospital\model\doctor;
use app\hospital\model\subjecttype;
class Booking extends BaseController{
    function index(){
        if(!Session::has('admin')){
            return Redirect('/index.php/hospital/admin/login');
        }
        $menu1=Db::name("menu")->order('did','asc')->where("type",0)->select();
        $menu2=Db::name("menu")->where("type","<>",0)->select();
        $dt=Db::name("subjecttype")->select();
        $m3=Db::name("subjecttype")->select();
        View::assign(['menu1'=>$menu1,'menu2'=>$menu2,'m3'=>$m3,'dt'=>$dt,'time'=>date("Y-m-d",time()),'admin'=>Session::get('admin')]);
        return View::fetch();
    }
    function list(){
        $key=Request::param('key');
        $d=new doctor();
        if(!empty($key)){
            $data=$d->search();
        }else{
            $data=$d->paginate(5);
        }
        View::assign('data',$data);
        return View::fetch();
    }
    function update(){
        $data=Request::post();
        $d=new doctor();
        $res=$d->update($data);
//        $res=Db::table('doctor')->update($data);
        if(!empty($res)){
            return 1;
        }else{
            return 0;
        }
//        return ($res);
    }
    function edit(){
        $id=Request::get('id');
        $d=new doctor();
        $data=$d->find($id);
//        $data=Db::table('doctor')->find($id);
        return json($data);
    }
    public function insert(){
        $p=Request::post();
        $d=new doctor();
        $res=$d->insert($p);
//        $res=Db::table('doctor')->insert($p);
        if(!empty($res)){
            return 1;
        }else{
            return 0;
        }
//        dump($p);
//        dump($res);
        return $res;
    }
    public function del(){
        $id=Request::param('id');
        $d=new doctor();
//        $res=Db::table('doctor')->delete($id);
        $res=$d->del();
//        if(!empty($res)){
//            return 1;
//        }else{
//            return 0;
//        }
        return $res;
    }
    public function insertsubject(){
        $p=Request::post();
        $d=new subjecttype();
        $res=$d->insert($p);
//        $res=Db::table('subjecttype')->insert($p);
        if(!empty($res)){
            return 1;
        }else{
            return 0;
        }
//        dump($p);
//        dump($res);
//        return $res;
    }
    public function insertdoctoruser(){
        $p=Request::post();
        $d=new doctoruser();
        $res=$d->insert($p);
//        $res=Db::table('subjecttype')->insert($p);
        if(!empty($res)){
            return 1;
        }else{
            return 0;
        }
//        dump($p);
//        dump($res);
//        return $res;
    }
}
